<!--
 * @Author: C.
 * @Date: 2023-03-27 10:55:48
-->
<!--
 * @Author: C.
 * @Date: 2023-02-02 09:40:43
-->
<template>
  <PageWrapper dense>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="handleCreate">新增数据</a-button>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                icon: 'ant-design:delete-outlined',
                color: 'error',
                tooltip: '删除此账号',
                popConfirm: {
                  title: '是否确认删除',
                  placement: 'left',
                  confirm: handleDelete.bind(null, record),
                },
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
  </PageWrapper>
</template>
<script lang="ts" setup name="listDemo">
  import { unref } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { createData, formSchemas, tableColumns } from './config';

  import { PageWrapper } from '/@/components/Page';
  const [registerTable, { insertTableDataRecord, deleteTableDataRecord }] = useTable({
    dataSource: createData(2),
    title: '混合编辑表格',
    useSearchForm: true,
    showTableSetting: true,
    // 开启键盘导航
    editKeyboard: true,
    columns: tableColumns,
    autoCreateKey: true,
    canResize: true,
    formConfig: {
      labelWidth: 120,
      schemas: formSchemas,
      autoSubmitOnEnter: true,
    },
    tableSetting: {
      import: true,
    },
    actionColumn: {
      width: 160,
      title: 'Action',
      dataIndex: 'action',
      fixed: 'right',
    },
  });

  async function handleDelete(record: Recordable) {
    deleteTableDataRecord(unref(record).key);
  }
  function handleCreate() {
    insertTableDataRecord(createData(1));
  }
</script>
<style lang="less" scoped></style>
